package com.haierp.service.purchase.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.haierp.mapper.ReceiptMapper;
import com.haierp.mapper.TaskReceiptMapper;
import com.haierp.model.Item;
import com.haierp.model.purchase.Receipt;
import com.haierp.model.purchase.TaskReceipt;
import com.haierp.service.authority.IUserServiceHai;
import com.haierp.service.purchase.IReceiptService;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.ReceiptQueryVO;
import com.haierp.vo.authority.UserQueryVO;

@Service
public class ReceiptServiceImpl extends SuperServiceImpl<ReceiptMapper, Receipt> implements IReceiptService {
	@Autowired
	IUserServiceHai userServiceHai;
	@Override
	public JsonPageResult<List<Receipt>> queryReceipt(ReceiptQueryVO receiptQueryVO) {
		JsonPageResult<List<Receipt>> receiptResult = new JsonPageResult<>();
		//1、查询总的记录数量
		Integer totalCount =  this.baseMapper.queryReceiptCount(receiptQueryVO);
		
		//2、查询分页记录
		if(totalCount!=null&&totalCount!=0){
			receiptResult.buildPage(totalCount, receiptQueryVO);
			List<Receipt> receipts = this.baseMapper.queryReceipt(receiptQueryVO);
			receiptResult.setData(receipts);
		}else{
			List<Receipt> receipts  = new ArrayList<>();
			receiptResult.setData(receipts);
		}
		return receiptResult;
	}

	/*@Autowired
	private TaskReceiptMapper taskReceiptMapper;
	
	@Override
	public void createReceipt(Receipt receipt) {
		
		this.baseMapper.insert(receipt);
		 List<TaskReceipt>  taskReceipts = receipt.getTaskReceiptList();
		 taskReceipts.forEach(
				 taskReceipt->taskReceipt.setReceiptId(receipt.getId())
				 );
		 taskReceiptMapper.insertBatch(taskReceipts);
	}*/


}
